//auto gen by paipai.java.augogen ver 1.0
//auther wendyhu
#ifndef _COOPERATORAO_COOPERATOR_H_
#define _COOPERATORAO_COOPERATOR_H_

#include <stdint.h>
#include <string>
#include <iostream>
#include "app_platform/help_macros.h"
#include "app_platform/intf_service.h"
#include "intf_cooperatorao.h"

#include "app_comm/uin_limit.h"
#include "library/basic/singleton_t.h"
#include "library/basic/sync_lock.h"
#include "c2cent/library/log/CWTimeElf3.h"
#include "c2cplatform/library/the3/jsoncpp/json.h"

#include <set>
#include <vector>
#include "b2b2c/cooperator/po/cooperatorbaseinfopo_cooperator.h"
#include "b2b2c/cooperator/po/cooperatorlicensepo_cooperator.h"
#include "b2b2c/cooperator/po/cooperatormonitormodelpo_cooperator.h"
#include "b2b2c/cooperator/po/cooperatorpropo_cooperator.h"
#include "b2b2c/cooperator/po/cooperatorsetpo_cooperator.h"
#include "b2b2c/cooperator/ddo/cooperatorsetddo_cooperator.h"
#include "b2b2c/cooperator/ddo/cooperatorbaseinfoddo_cooperator.h"
#include "b2b2c/cooperator/ddo/cooperatorproddo_cooperator.h"
#include "b2b2c/nca/ddo/navddo_nca.h"

namespace b2b2c
{
namespace cooperator
{
namespace ao
{


SERVICE class CCooperatorAo : public ICooperatorAo{
public:
		CCooperatorAo(enum DeployMethod method = DEPLOY_STANDALONE);
		~CCooperatorAo();

		void Reset();
		static int Initialize(IUserDefineCntl* pCntl = NULL);

public:
	 /**
	 *
	 *   更新【新增和修改】合作伙伴基本信息
	 *
	 */
	EXPORT(0xA0121804) uint32_t UpdateCooperatorBaseInfo(
		 const CCntlInfo& rCntlInfo,
		 const std::string& strMachineKey,
		 const std::string& strSource,
		 uint32_t dwSceneId,
		 const b2b2c::cooperator::po::CCooperatorBaseInfoPo& oCooperatorBaseInfoPo,
		 const std::string& strInReserve,
		 std::string& strErrmsg,
		 std::string& strOutReserve
		);

	 /**
	 *
	 *   设置合作伙伴密码信息
	 *
	 */
	EXPORT(0xA0121805) uint32_t SetCooperatorPassWd(
		 const CCntlInfo& rCntlInfo,
		 const std::string& strMachineKey,
		 const std::string& strSource,
		 uint32_t dwSceneId,
		 uint64_t ddwCooperatorId,
		 const std::string& strCooperatorOldPassword,
		 const std::string& strCooperatorNewPassword,
		 const std::string& strInReserve,
		 std::string& strErrmsg,
		 std::string& strOutReserve
		);

	 /**
	 *
	 *   更新【新增和修改】合作伙伴许可证信息
	 *
	 */
	EXPORT(0xA0121806) uint32_t UpdateCooperatorLicense(
		 const CCntlInfo& rCntlInfo,
		 const std::string& strMachineKey,
		 const std::string& strSource,
		 uint32_t dwSceneId,
		 const b2b2c::cooperator::po::CCooperatorLicensePo& oCooperatorLicensePo,
		 const std::string& strInReserve,
		 std::string& strErrmsg,
		 std::string& strOutReserve
		);

	 /**
	 *
	 *   获取合作伙伴许可证信息
	 *
	 */
	EXPORT(0xA0121802) uint32_t GetCooperatorLicense(
		 const CCntlInfo& rCntlInfo,
		 const std::string& strMachineKey,
		 const std::string& strSource,
		 uint32_t dwSceneId,
		 uint64_t ddwCooperatorId,
		 const std::set<uint8_t> & setLicenseType,
		 const std::string& strInReserve,
		 std::string& strErrmsg,
		 std::vector<b2b2c::cooperator::po::CCooperatorLicensePo> & vecCooperatorLicensePo,
		 std::string& strOutReserve
		);

	/**
     *
     *   获取合作伙伴基本信息，该接口没进行操作者验证和鉴权，合作伙伴敏感信息无法拉取
     *
     */
	EXPORT(0xA0121801) uint32_t GetCooperatorBaseInfo(
		 const CCntlInfo& rCntlInfo,
		 const std::string& strMachineKey,
		 const std::string& strSource,
		 uint32_t dwSceneId,
		 uint64_t ddwCooperatorId,
		 const std::string& strInReserve,
		 std::string& strErrmsg,
		 b2b2c::cooperator::po::CCooperatorBaseInfoPo& oCooperatorBaseInfoPo,
		 std::string& strOutReserve
		);

	 /**
	 *
	 *   检查合作伙伴密码信息
	 *
	 */
	EXPORT(0xA0121803) uint32_t CheckCooperatorPassWd(
		 const CCntlInfo& rCntlInfo,
		 const std::string& strMachineKey,
		 const std::string& strSource,
		 uint32_t dwSceneId,
		 uint64_t ddwCooperatorId,
		 const std::string& strCooperatorPassword,
		 const std::string& strInReserve,
		 std::string& strErrmsg,
		 std::string& strOutReserve
		);

	/**
     *
     *   获取合作伙伴数据加密Key
     *
     */
    EXPORT(0xA0121808) uint32_t GetCooperatorKey(
         const CCntlInfo& rCntlInfo,
         const std::string& strMachineKey,
         const std::string& strSource,
         uint32_t dwSceneId,
         uint64_t ddwCooperatorId,
         const std::string& strInReserve,
         std::string& strErrmsg,
         std::string& strSCooperatorKey,
         std::string& strOutReserve
        );

	/**
     *
     *   批量获取合作伙伴基本信息
     *
     */
    EXPORT(0xA0121807) uint32_t GetCooperatorBaseInfoList(
         const CCntlInfo& rCntlInfo,
         const std::string& strMachineKey,
         const std::string& strSource,
         uint32_t dwSceneId,
         const std::set<uint64_t> & setCooperatorId,
         const std::string& strInReserve,
         std::string& strErrmsg,
         std::vector<b2b2c::cooperator::po::CCooperatorBaseInfoPo> & vecCooperatorBaseInfoPo,
         std::string& strOutReserve
        );

    /**
    *
    *   支付物流系统设置卖家的次日达，货到付款等属性位接口
    *
    */
   EXPORT(0xA0121809) uint32_t LogisticsSetCooperatorPro(
        const CCntlInfo& rCntlInfo,
        const std::string& strMachineKey,
        const std::string& strSource,
        uint32_t dwSceneId,
        uint64_t ddwOption,
        const b2b2c::cooperator::po::CCooperatorProPo& oCooperatorProPo,
        const std::string& strInReserve,
        std::string& strErrmsg,
        b2b2c::cooperator::po::CCooperatorBaseInfoPo& oCooperatorBaseInfoPo,
        std::string& strOutReserve
       );

   /**
      *
      *   从管理后台等其他业务同步过来的设置合作伙伴属性位等信息的接口
      *
      */
     EXPORT(0xA012180A) uint32_t SetCooperatorInfo(
          const CCntlInfo& rCntlInfo,
          const std::string& strMachineKey,
          const std::string& strSource,
          uint32_t dwSceneId,
          uint64_t ddwOption,
          const b2b2c::cooperator::po::CCooperatorSetPo& oCooperatorSetPo,
          const std::string& strInReserve,
          std::string& strErrmsg,
          b2b2c::cooperator::po::CCooperatorBaseInfoPo& oCooperatorBaseInfoPo,
          std::string& strOutReserve
         );


	 /**
	 *
	 *   删除告警模版
	 *
	 */
	EXPORT(0xA012180E) uint32_t DeleteCooperatorMonitorModel(
		 const CCntlInfo& rCntlInfo,
		 const std::string& strMachineKey,
		 const std::string& strSource,
		 uint32_t dwSceneId,
		 uint32_t dwCooperatorId,
		 uint32_t dwModelId,
		 const std::string& strInReserve,
		 std::string& strErrmsg,
		 std::string& strOutReserve
		);

	 /**
	 *
	 *   通过模版ID获取告警模版
	 *
	 */
	EXPORT(0xA012180C) uint32_t GetCooperatorMonitorModel(
		 const CCntlInfo& rCntlInfo,
		 const std::string& strMachineKey,
		 const std::string& strSource,
		 uint32_t dwSceneId,
		 uint32_t dwCooperatorId,
		 uint32_t dwModelId,
		 const std::string& strInReserve,
		 std::string& strErrmsg,
		 b2b2c::cooperator::po::CCooperatorMonitorModelPo& oCooperatorMonitorModelPo,
		 std::string& strOutReserve
		);

		/**
		 *
		 *   获取价格告警模版列表
		 *
		 */
		EXPORT(0xA012180B) uint32_t GetCooperatorMonitorModelList(
			 const CCntlInfo& rCntlInfo,
			 const std::string& strMachineKey,
			 const std::string& strSource,
			 uint32_t dwSceneId,
			 uint32_t dwCooperatorId,
			 const std::string& strInReserve,
			 std::string& strErrmsg,
			 std::vector<b2b2c::cooperator::po::CCooperatorMonitorModelPo> & vecCooperatorMonitorModelPo,
			 std::string& strRulesruleJson,
			 std::string& strOutReserve
			);

	 /**
	 *
	 *   新增或者更新告警模版
	 *
	 */
	EXPORT(0xA012180D) uint32_t UpdateCooperatorMonitorModel(
		 const CCntlInfo& rCntlInfo,
		 const std::string& strMachineKey,
		 const std::string& strSource,
		 uint32_t dwSceneId,
		 const b2b2c::cooperator::po::CCooperatorMonitorModelPo& oCooperatorMonitorModelPo,
		 const std::string& strInReserve,
		 std::string& strErrmsg,
		 std::string& strOutReserve
		);
		
    /**
	 *
	 *   根据ERP商户id查询合作伙伴ID
	 *
	 */
	EXPORT(0xA012180F) uint32_t GetCooperatorIdByIcsonId(
		 const CCntlInfo& rCntlInfo,
		 const std::string& strMachineKey,
		 const std::string& strSource,
		 uint32_t dwSceneId,
		 uint64_t ddwIcsonId,
		 const std::string& strInReserve,
		 std::string& strErrmsg,
		 uint64_t& ddwCooperatorId,
		 std::string& strOutReserve
		);

private:
    /**
     *
     * 初始化TMEM
     *@return  uint32_t : 0(成功) 其它失败
     *
     */
    static int32_t InitTMEM(IUserDefineCntl* pCntl = NULL);
    static int32_t InitMonitorRuleCfg(IUserDefineCntl* pCntl = NULL);

    int32_t _CheckRequest();

    int32_t _ParameterCheckCooperatorProPo(const b2b2c::cooperator::po::CCooperatorProPo& oCooperatorProPo);
    int32_t _ParameterCheckCooperatorSubProPo(const b2b2c::cooperator::po::CCooperatorSubProPo& oCooperatorSubProPo);
    int32_t _ParameterCheckForBaseInfo(const b2b2c::cooperator::po::CCooperatorBaseInfoPo& oCooperatorBaseInfoPo);

    int32_t _ParameterCheckForLicense(const b2b2c::cooperator::po::CCooperatorLicensePo& oCooperatorLicensePo);

    int32_t _UpdateCooperatorBaseInfo(const CCntlInfo& rCntlInfo,
                                    const b2b2c::cooperator::ddo::CCooperatorBaseInfoDdo oCooperatorBaseInfoDdo,
                                    c2cent::library::wtimeelf::CWTimeElfItil& oWTimeElf);

    int32_t _GetCooperatorBaseInfo4MsgQKeylog(const CCntlInfo& rCntlInfo,
                                    const std::string& strMachineKey,
                                    uint32_t dwSceneId,
                                    const std::string& strSource,
                                    uint8_t cFlag,
                                    uint32_t dwCooperatorId,
                                    b2b2c::cooperator::po::CCooperatorBaseInfoPo& oCooperatorBaseInfoPo,
                                    c2cent::library::wtimeelf::CWTimeElfItil& oWTimeElf);

   int32_t _SendSendCooperatorBaseInfoEventMsgq( const CCntlInfo& rCntlInfo,
                                                    uint32_t sceneId,
                                                    uint32_t operatorId,
                                                    uint32_t dwOperationType,
                                                    std::set<uint32_t> setEventId,
                                                    uint32_t eventLevel,
                                                    const b2b2c::cooperator::po::CCooperatorBaseInfoPo& oCooperatorBaseInfoPoBefore,
                                                    const b2b2c::cooperator::po::CCooperatorBaseInfoPo& oCooperatorBaseInfoPoAfter,
                                                    c2cent::library::wtimeelf::CWTimeElfItil& oWTimeElf);

   int32_t _GetCooperatorLicenseInfo4MsgQKeylog(
           const CCntlInfo& rCntlInfo,
            uint8_t cFlag,
            uint64_t ddwCooperatorId,
            std::vector<b2b2c::cooperator::po::CCooperatorLicensePo>& vecCooperatorLicensePo,
            std::string& strOutReserve,
            c2cent::library::wtimeelf::CWTimeElfItil& oWTimeElf);

   void _GetCooperatorLicenseInfoMsgQSetEventId(
            std::vector<b2b2c::cooperator::po::CCooperatorLicensePo>& vecCooperatorLicensePoBefore,
            std::vector<b2b2c::cooperator::po::CCooperatorLicensePo>& vecCooperatorLicensePoAfter,
            std::set<uint32_t>& setEventId);

   int32_t _SendSendCooperatorLicenseInfoEventMsgq( const CCntlInfo& rCntlInfo,
                                                           uint32_t sceneId,
                                                           uint32_t operatorId,
                                                           uint32_t dwOperationType,
                                                           std::set<uint32_t> setEventId,
                                                           uint32_t eventLevel,
                                                           const std::vector<b2b2c::cooperator::po::CCooperatorLicensePo>& vecCooperatorLicensePoBefore,
                                                           const std::vector<b2b2c::cooperator::po::CCooperatorLicensePo>& vecCooperatorLicensePoAfter,
                                                           c2cent::library::wtimeelf::CWTimeElfItil& oWTimeElf);

   int32_t _SendSendCooperatorSubAccountInfoEventMsgq( const CCntlInfo& rCntlInfo,
                                                           uint32_t sceneId,
                                                           uint32_t operatorId,
                                                           uint32_t dwOperationType,
                                                           std::set<uint32_t> setEventId,
                                                           uint32_t eventLevel,
                                                           const std::vector<b2b2c::cooperator::po::CCooperatorSubAccountPo>& vecCooperatorSubAccountPoBefore,
                                                           const std::vector<b2b2c::cooperator::po::CCooperatorSubAccountPo>& vecCooperatorSubAccountPoAfter,
                                                           c2cent::library::wtimeelf::CWTimeElfItil& oWTimeElf);

   int32_t _GetNode(const CCntlInfo& rCntlInfo,
                       uint32_t dwNodeId, //品类或者一级类目ID
                       b2b2c::nca::ddo::CNavDdo& navDdo,
                       c2cent::library::wtimeelf::CWTimeElfItil& oWTimeElf);

   int32_t _SetCooperatorPro(const CCntlInfo& rCntlInfo,
                                   uint64_t ddwOption,
                                   const b2b2c::cooperator::ddo::CCooperatorProDdo& oCooperatorProDdo,
                                   c2cent::library::wtimeelf::CWTimeElfItil& oWTimeElf);

   int32_t _SetCooperatorInfo(const CCntlInfo& rCntlInfo,
                                   uint64_t ddwOption,
                                   const b2b2c::cooperator::ddo::CCooperatorSetDdo oCooperatorSetDdo,
                                   c2cent::library::wtimeelf::CWTimeElfItil& oWTimeElf);
   int32_t _GetModelRuleInfo(
		   const b2b2c::cooperator::po::CCooperatorMonitorModelPo& oCooperatorMonitorModelPo,
		   std::string& strModelRule
   );

private:
    static c2cent::library::wtimeelf::CItilGroup m_oUpdateCooperatorBaseInfoGroup;
    static c2cent::library::wtimeelf::CItilGroup m_oGetCooperatorLicenseGroup;
    static c2cent::library::wtimeelf::CItilGroup m_oGetCooperatorBaseInfoGroup;
    static c2cent::library::wtimeelf::CItilGroup m_oSetCooperatorPassWdGroup;
    static c2cent::library::wtimeelf::CItilGroup m_oCheckCooperatorPassWdGroup;
    static c2cent::library::wtimeelf::CItilGroup m_oUpdateCooperatorLicenseGroup;
    static c2cent::library::wtimeelf::CItilGroup m_oSendCooperatorSubAccountInfoEventMsgq;
    static c2cent::library::wtimeelf::CItilGroup m_oSendCooperatorLicenseInfoEventMsgq;
    static c2cent::library::wtimeelf::CItilGroup m_oGetCooperatorLicenseInfo4MsgQKeylog;
    static c2cent::library::wtimeelf::CItilGroup m_oSendCooperatorBaseInfoEventMsgq;
    static c2cent::library::wtimeelf::CItilGroup m_oGetCooperatorBaseInfo4MsgQKeylog;
    static c2cent::library::wtimeelf::CItilGroup m_oGetNode;
    static c2cent::library::wtimeelf::CItilGroup m_oGetCooperatorBaseInfoList;
    static c2cent::library::wtimeelf::CItilGroup m_oGetCooperatorKey;
    static c2cent::library::wtimeelf::CItilGroup m_oLogisticsSetCooperatorPro;
    static c2cent::library::wtimeelf::CItilGroup m_oSetCooperatorInfo;

    static c2cent::library::wtimeelf::CItilGroup m_oGetDataFromTmemGroup;
    static c2cent::library::wtimeelf::CItilGroup m_oGetMonitorModelListGroup;
	static c2cent::library::wtimeelf::CItilGroup m_oGetMonitorModelGroup;
	static c2cent::library::wtimeelf::CItilGroup m_oUpdateMonitorModelGroup;
	static c2cent::library::wtimeelf::CItilGroup m_oDeleteMonitorModelGroup;
    static c2cent::library::wtimeelf::CItilGroup m_oGetCooperatorIDGroup;

	enum DeployMethod m_method;
    uint32_t m_dwOperatorUin;
    uint32_t m_dwSceneId;
    std::string m_strMachineKey;
    std::string m_strSource;
    static std::set<uint16_t> m_setLogisticsPro;

    static std::string m_monitorSysRule;//系统规则字符串
    static Json::Value m_monitorRuleCfg;//规则配置情况
    static std::string m_monitorRuleJson;//规则配置JSON字符串
    static std::map<std::string,Json::Value> m_monitorRuleMap;

private:
    template <class InputIterator, typename TT>
    InputIterator find(
      InputIterator first, InputIterator last, const TT& value) {
         while (first != last && (*first).GetCooperatorSubAccountId() != (value).GetCooperatorSubAccountId()) ++first;
         return first;
      }

    template <class InputIterator, typename TT>
    InputIterator findLicense(
      InputIterator first, InputIterator last, const TT& value) {
         while (first != last && ((*first).GetCooperatorId() != (value).GetCooperatorId() &&
                 (*first).GetLicenseType() != (value).GetLicenseType()) ) ++first;
         return first;
      }
};

}
}
}

#endif /* _COOPERATORAO_COOPERATOR_H_ */
